﻿using System.Web.Mvc;
using Deepcode.ValidationSample.Models;

namespace Deepcode.ValidationSample.Controllers
{
	[HandleError]
	public class SimpleFormController : Controller
	{
		[HttpGet]
		public ActionResult Index()
		{
			return View(new BookViewModel());
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public ActionResult PostFormData( BookViewModel model )
		{
			if( ! ModelState.IsValid )
				return View("Index", model);

			// Passed validation - just restart the form
			return RedirectToAction("Index");
		}
	}
}
